package com.etc.zmall.dao.impl;

import java.util.List;

import com.etc.util.DBUtil;
import com.etc.util.PageData;
import com.etc.zmall.dao.ItemsDao;
import com.etc.zmall.entity.Items;

/**
 * ItemsDaoImpl
 * @author Administrator
 *
 */
public class ItemsDaoImpl implements ItemsDao{
	//新增订单项 
	@Override
	public boolean addItems(Items items) {
		String sql="insert into tbl_items values(null,?,?,?,?)";
		return DBUtil.exUpdate(sql, items.getCount(),items.getGoodsid(),items.getOrderid(),items.getCost());
	}
	//删除订单项
	@Override
	public boolean delItems(int itemsid) {
		String sql="delete from tbl_items where itemsid=?";
		return DBUtil.exUpdate(sql, itemsid);
	}
	//修改订单项中的数量和花费
	@Override
	public boolean UpItems(int count,double cost,int itemsid) {
		String sql="update tbl_items set count=? ,cost=? where itemsid=?";
		return DBUtil.exUpdate(sql, count,cost,itemsid);
	}
	//查看商店中的所有订单项
	@Override
	public PageData <Items> queryItemsShop(int page, int pageSize, int shopid) {
		String sql="select * from tbl_items  where goodsid in (select goodsid from tbl_goods  where shopid=1)";
		return DBUtil.exQueryByPage(sql, Items.class, page, pageSize, shopid);
	}
	//商店中单一商品的订单项
	@Override
	public PageData <Items> queryItemsGoods(int page, int pageSize, int goodsid) {
		String sql="select * from tbl_items  where goodsid=?";
		return DBUtil.exQueryByPage(sql, Items.class, page, pageSize, goodsid);
	}
	//查看订单(一个订单下的多个订单项)
	@Override
	public PageData <Items>queryItemsOrder(int page, int pageSize, int orderid) {
		String sql="select * from tbl_items  where orderid=?";
		return DBUtil.exQueryByPage(sql, Items.class, page, pageSize, orderid);
	}
	//查看订单项详情
	@Override
	public Items queryOneItems(int itemsid) {
		String sql="select * from tbl_items  where itemsid=?";
				
		List<Items > list =  (List<Items>) DBUtil.exQuery(sql, Items.class, itemsid);
		if (list.size() == 0) {
			return null;
		}
		return list.get(0);
		
	}

}
